<?php
session_start();
if(!ob_start("ob_gzhandler")) ob_start();
?>
<html>
	<head>
		<title></title>
		<link rel = "stylesheet" type = "text/css" href = "mainFrame.css">
		<link rel = "stylesheet" type = "text/css" href = "chatStyl.css">
		<script type='text/javascript' src='jquery-1.7.js'></script>
		<script type = 'text/javascript' src = 'jquery-ui-1.8.16.custom.min.js'></script>
	</head>
		<body>
		<?php
	mysql_connect("localhost", "sapmenet_admin", "a1s2d3f4g5h6j7") or die ("Problem with datebase");
	mysql_select_db("sapmenet_users");

	if (isset($_SESSION['JID']))
	{
		
	}
	else{
		header ('Location: ../index.php');
		exit();
	}
	?>
		<div id = "showChat" title = "Show chat">
			<img id = "showChatArrow" src = "Icons/showChatUp.gif">
		</div>
		<div id = 'chatOnlineUsersDialog'>
			<div id = "chatUsersOnlineHeaderless">
			</div>
		</div>
		<div class = "singleChatDialog">
			<div class = "chatWindowHeader" id = "zaek">
				<h3 id = 'interlocutorHeaderNameText'></h3>
				<img src = "Icons/close.png" class = "closeChatWindowButton">
				<div class = "clear">
				</div>
			</div>
			<div class = "chatDialogHeaderless">
				<div class = "theThingsInLeft">
					<div class = "messagesField">
					</div>
					<div class = "messageInputBox">
						<input type = "text" class = "newMessage"/><button class = "newMessageButton">Send</button>
					</div>
				</div>
				<div class = "chatPfffPicture">	
				</div>
				<div class = "clear">
				</div>
			</div>
		</div>
		<script>
			$.post("onlineUsers.php");
			$("#chatOnlineUsersDialog").draggable("destroy");
			$(".singleChatDialog").draggable({handle : ".chatWindowHeader"});
			var isHere = false;
			$("#showChat").click(function()
			{
				if(!isHere)
				{
					$("#chatUsersOnlineHeaderless").load("friendUsersOnline.php");
					$("#chatOnlineUsersDialog").show("explode");
					isHere = true;
					$("#showChat").attr("title", "Hide chat");
					$("#showChatArrow").attr("src", "Icons/showChatDown.gif");
				}
				else
				{
					$("#chatOnlineUsersDialog").hide("explode");
					isHere = false;
					$("#showChat").attr("title", "Show chat");
					$("#showChatArrow").attr("src", "Icons/showChatUp.gif");
				}
				
			});
			$(".closeChatWindowButton").click(function()
			{
				$(".singleChatDialog").hide("explode");
				$(".chatWindowHeader h3").html("");
				$(".chatWindowHeader").attr("id", "zaek");
			});
			$(".newMessageButton").click(function()
			{
				var mes = $(".newMessage").val();
				var to = $(".chatWindowHeader").attr("id");
				var text = $(".newMessage").val();
				$(".newMessage").val("");
				$.post("sendNewChatMessage.php", {to : to, text : text}, function()
				{
					$.post("showMessages.php", {ot : to}, function(data)
					{
						$(".messagesField").html(data);
						$(".messagesField").scrollTop($(".messagesField")[0].scrollHeight);
					});
				});
			});
			$(".newMessage").keypress(function(e)
			{
				if(e.keyCode == 13)
				{
					var mes = $(".newMessage").val();
					var to = $(".chatWindowHeader").attr("id");
					var text = $(".newMessage").val();
					$(".newMessage").val("");
					$.post("sendNewChatMessage.php", {to : to, text : text}, function()
					{
						$.post("showMessages.php", {ot : to}, function(data)
						{
							$(".messagesField").html(data);
							$(".messagesField").scrollTop($(".messagesField")[0].scrollHeight);
						});
					});
				}
			});
			function checkForNewMessages()
			{
				$.post("checkForNewChatMessages.php", function(data)
				{
					if(data!="HUI")
					{
						var to = $(".chatWindowHeader").attr("id");
						$.post("showNewChatMessages.php", {ot : to}, function(theData)
						{
							$(".messagesField").append(theData);
							$(".messagesField").scrollTop($(".messagesField")[0].scrollHeight);
						});
					}
				});
			}
			function makeOnline()
			{
				$.post("onlineUsers.php");
			}
			setInterval("makeOnline()", 120000);
			setInterval("checkForNewMessages()", 3000);
		</script>
		</body>
</html>		



























































